//
//  CustomScreenMenuModel.m
//  PigMarket
//
//  Created by 张敬 on 2019/7/31.
//  Copyright © 2019年 pigmarket.oc. All rights reserved.
//

#import "CustomScreenMenuModel.h"

@implementation CustomScreenMenuModel

- (NSArray <CustomScreenMenuItem *> *)datas{
    
    if (!_datas) {
        
        _datas = [NSArray array];
        
        __block NSMutableArray *aims = [NSMutableArray array];
        __block float totalwidth = 0.f;
        
        @weakify(self);
        [self.titles enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            @strongify(self);
            
            UILabel *label = [[UILabel alloc] init];
            label.frame = CGRectMake(0, 0, KScreenWidth, 44);
            NSMutableAttributedString *atttibutedStr = [obj createAttributingByIcon:nil downIndexImage:self.nomalIcons[idx] textColor:UIColorFromRGB(0x333333) font:mFont(14)];
            label.attributedText = atttibutedStr;
            [label sizeToFit];
            
            
            //刚选择
            NSMutableAttributedString *selectedAtttibutedStr = [obj createAttributingByIcon:nil downIndexImage:self.selectedIcons[idx] textColor:mMainColor font:mMediumFont(14)];
            
            //再次选择
            NSMutableAttributedString *doubleSelectedAtttibutedStr = [obj createAttributingByIcon:nil downIndexImage:self.doubleSelectedIcons[idx] textColor:mMainColor font:mMediumFont(14)];
            
            
            CGSize size = label.size;
            totalwidth += size.width;
            
            CustomScreenMenuItem *item = [[CustomScreenMenuItem alloc] init];
            
            item.textW = size.width;
            item.text = atttibutedStr;
            item.selectedText = selectedAtttibutedStr;
            item.doubleSelectionText = doubleSelectedAtttibutedStr;
            
            
            //类别
            if(idx == 0) item.type = CustomScreenMenuType_default;
            if(idx == 1) item.type = CustomScreenMenuType_Price;
            if(idx == 2) item.type = CustomScreenMenuType_ShopOwns;
            if(idx == 3) item.type = CustomScreenMenuType_SendDate;
            if(idx == 4) item.type = CustomScreenMenuType_Screening;

            
            [aims addObject:item];
            
        }];
        
        
        __block float textOffsetX = 15.f;
        __block float gap = (KScreenWidth - 30 - totalwidth)/(self.titles.count -1);
        __block float textTotalW = 0.f;
        
        [aims enumerateObjectsUsingBlock:^(id  _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
            
            CustomScreenMenuItem *item = (CustomScreenMenuItem *)obj;
            item.textOffsetX = gap *idx + textTotalW  + textOffsetX;
            textTotalW += item.textW;
            
        }];
        
        _datas = [aims copy];
        
    }
    return _datas;
}



@end




@implementation CustomScreenMenuItem

@end



@implementation ScreenItem

- (NSArray <NSNumber *> *)tags{
    
    if (!_tags) {
        _tags = [NSArray array];
        
       __block NSMutableArray *aims = [NSMutableArray array];
        if (self.subTitles && self.subTitles.count>0) {
            
            [self.subTitles enumerateObjectsUsingBlock:^(NSString * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
                NSNumber *number = idx == 0 ?@1 :@0;
                [aims addObject:number];
            }];
        }
        
        _tags = [aims copy];
    }
    return _tags;
}


- (NSInteger)currentItem{
    
    if (!_currentItem) {
        _currentItem = 0;
    }
    return _currentItem;
}


@end







